from bs4 import BeautifulSoup

html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><b>The Dormouse's story</b></p>

<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>

<p class="story">...</p>
"""
soup = BeautifulSoup(html_doc, 'lxml')
# print(soup.prettify())
# print(soup.get_text())
# print(soup.title.name)
# print(soup.title.string)
# print(soup.p['class'])
# print(soup.a)
# print(soup.find_all('a'))   #通过标签获取
# for link in soup.find_all('a'):     #获取所有a标签的链接
#     print(link.get('href'))

# css搜索
# print(soup.find_all("a", class_="sister"))      #通过css类名, 注意: 参数是class_, 有下划线
# #class_参数接受不同类型的过滤器, 包括正则表达式, 方法, 字符串, True
# print(soup.find_all(class_ = re.compile('itl')))
# def has_six_characters(css_class):
#     return css_class is not None and len(css_class) == 6
# print(soup.find_all(class_=has_six_characters))
# print(soup.find_all(class_ = 'sister'))

# text参数
print(soup.find_all(text='Elsie'))
